package br.com.californiahotel.client.viewControler.reserva;

import br.com.californiahotel.client.architecture.viewController.BasicView;
import br.com.californiahotel.client.viewControler.reserva.ReservaFormController.Display;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.DateItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;

public class ReservaFormView extends BasicView implements Display {

	public enum Field{
		DATE("Data"),HOSPEDE("Hospede"),APARTAMENTO("Apartamento"), SAVE("Salvar");

		private final String fieldName;

		private Field(String name) {
			fieldName = name;
		}

		public String getFieldName() {
			return fieldName;
		}

	}

	private DynamicForm form;

	public ReservaFormView() {
		mountForm();
		setAutoWidth();
		setHeight100();
		setMargin(20);
	}

	//	public ReservaFormView(Long cdServico, String description, Double value) {
	//		mountForm();
	//		setAutoWidth();
	//		setHeight100();
	//		setMargin(20);
	//		form.getItem(Field.HIDDEN.getFieldName()).setValue(cdServico);
	//		form.getItem(Field.DESCRIPTION.getFieldName()).setValue(description);
	//		form.getItem(Field.VALUE.getFieldName()).setValue(value.toString().replace(".", ","));
	//	}

	private void mountForm() {
		form = new DynamicForm();
		form.setShowEdges(true);

		DateItem dateItem = new DateItem(Field.DATE.getFieldName(), "Data");
		dateItem.setUseTextField(true);
		TextItem hospedeItem = new TextItem(Field.HOSPEDE.getFieldName(),"Hospede");
		SelectItem apComboBoxItem = new SelectItem(Field.APARTAMENTO.getFieldName(), "Apartamento");


		ButtonItem buttonItem = new ButtonItem(Field.SAVE.getFieldName(), "Salvar");
		buttonItem.setAlign(Alignment.RIGHT);
		buttonItem.setEndRow(false);
		buttonItem.setStartRow(false);

		form.setCellPadding(5);
		form.setFields(dateItem, hospedeItem, apComboBoxItem, new SpacerItem(), buttonItem);
		addChild(form);
	}

	@Override
	public DynamicForm getForm() {
		return form;
	}

}
